unit UDraw;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Menus, Vcl.ExtCtrls, Vcl.Buttons,
  Vcl.ExtDlgs, Vcl.StdCtrls;

type


  TMyDraw = class(TForm)
    MainMenu1: TMainMenu;
    FileMenu: TMenuItem;
    Exit1: TMenuItem;
    Panel1: TPanel;
    Pencil: TSpeedButton;
    Image1: TImage;
    SaveAs1: TMenuItem;
    SaveDialog1: TSaveDialog;
    OpenPictureDialog1: TOpenPictureDialog;
    Open1: TMenuItem;
    ColorDialog1: TColorDialog;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    procedure Exit1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SaveAs1Click(Sender: TObject);
    procedure Open1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public

  end;

var
  MyDraw: TMyDraw;
  IsDrawing : Boolean;
  filename : String;

implementation

{$R *.dfm}

procedure TMyDraw.BitBtn1Click(Sender: TObject);
begin
//  Self.ColorDialog1.Execute();
//  Self.Image1.Canvas.Pen.Color := Self.ColorDialog1.Color;
end;

procedure TMyDraw.Exit1Click(Sender: TObject);
begin
  MyDraw.Close;
end;

procedure TMyDraw.FormCreate(Sender: TObject);
begin
  IsDrawing := False;
end;

procedure TMyDraw.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Image1.Canvas.MoveTo(x, y);

  if Pencil.Down then
    IsDrawing := True;

end;

procedure TMyDraw.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if IsDrawing then
    Image1.Canvas.LineTo( x, y );

end;

procedure TMyDraw.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  IsDrawing := False;
end;

procedure TMyDraw.Open1Click(Sender: TObject);
begin
   if OpenPictureDialog1.Execute then
   begin
     Self.OpenPictureDialog1.Filter := 'Bitmap  (*.bmp | *.BMP)';
     filename := Self.OpenPictureDialog1.FileName;
     Self.Image1.Picture.LoadFromFile(filename);
   end;
end;

procedure TMyDraw.SaveAs1Click(Sender: TObject);
begin
  SaveDialog1.DefaultExt := 'BMP';
  if SaveDialog1.Execute then
  begin
    //Saves the file
    filename := SaveDialog1.FileName;
    Image1.Picture.SaveToFile(filename);
  end;

end;

end.
